home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import os
- import errno
- import logging
- logger = logging.getLogger('ZODB.lock_file')
-
- try:
- import fcntl
- except ImportError:
-
- try:
- from winlock import LockFile as _LockFile
- from winlock import UnlockFile as _UnlockFile
- except ImportError:
-
- def lock_file(file):
- logger.info('No file-locking support on this platform')
-
-
-
- def lock_file(file):
- _LockFile(file.fileno(), 0, 0, 1, 0)
-
-
- def unlock_file(file):
- _UnlockFile(file.fileno(), 0, 0, 1, 0)
-
-
- _flags = fcntl.LOCK_EX | fcntl.LOCK_NB
-
- def lock_file(file):
- fcntl.flock(file.fileno(), _flags)
-
-
- def unlock_file(file):
- pass
-
-
- class LockFile:
-
- def __init__(self, path):
- self._path = path
-
- try:
- self._fp = open(path, 'r+')
- except IOError:
- e = None
- if e.errno != errno.ENOENT:
- raise
-
- self._fp = open(path, 'w+')
-
-
- try:
- lock_file(self._fp)
- except:
- logger.exception('Error locking file %s', path)
- raise
-
- print >>self._fp, os.getpid()
- self._fp.flush()
-
-
- def close(self):
- if self._fp is not None:
- unlock_file(self._fp)
- self._fp.close()
- os.unlink(self._path)
- self._fp = None
-
-
-
-